#define _CRT_SECURE_NO_WARNINGS

#include "string.h"
using namespace BLZ;

void test01()// operator[], iterator
{
	string str("hello world");
	int i = 0;
	for (i = 0; i < str.size(); i++)
	{
		cout << str[i] << ' ';
	}
	cout << endl;
	string::iterator it = str.begin();
	for (; it < str.end(); it++)
	{
		cout << *it << ' ';
	}
	cout << endl;
	for (auto e : str)
	{
		cout << e << ' ';
	}
	//cout << str << endl;

	const string str2 = "123456";
	auto it2 = str2.begin();
}

void test02()// push_back, append, operator+=
{
	string str1;
	str1.push_back('1');
	str1.push_back('1');
	str1.push_back('1');
	str1.push_back('1');
	str1.push_back('1');
	str1.push_back('1');
	str1.push_back('1');
	str1 += "222";
	str1 += '3';
	for (auto e : str1)
	{
		cout << e;
	}
	//cout << s1 << endl;
}

void test03()// insert, erase
{
	string str1 = "1234567";
	str1.insert(0, 'o');
	string str2 = "1234567";
	str2.insert(1, 'o');
	string str3 = "1234567";
	str3.insert(6, 'o');
	cout << str1.c_str() << endl;
	cout << str2.c_str() << endl;
	cout << str3.c_str() << endl;

	string str4 = "1234567";
	str4.insert(0, "xxx");
	string str5 = "1234567";
	str5.insert(1, "xxx");
	string str6 = "1234567";
	str6.insert(6, "xxx");
	cout << str4.c_str() << endl;
	cout << str5.c_str() << endl;
	cout << str6.c_str() << endl;

	string str7 = "1234567";
	str7.erase();
	string str8 = "1234567";
	str8.erase(1);
	string str9 = "1234567";
	str9.erase(1, 3);
	cout << str7.c_str() << endl;
	cout << str8.c_str() << endl;
	cout << str9.c_str() << endl;
}

void test04()// find, substr
{
	string str1 = "123456abcd";
	cout << "string:" << str1.c_str() << " find:\'a\', at pos: " << str1.find('a', 0) << endl;
	cout << "string:" << str1.c_str() << " find:\"abc\", at pos: " << str1.find("abc", 0) << endl;
	cout << "string:" << str1.c_str() << " find:\'1\', at pos: " << str1.find('1', 0) << endl;
	cout << "string:" << str1.c_str() << " find:\"123\", at pos: " << str1.find("123", 0) << endl;
	cout << "string:" << str1.c_str() << " find:\'d\', at pos: " << str1.find('d', 0) << endl;
	cout << "string:" << str1.c_str() << " find:\"d\", at pos: " << str1.find("d", 0) << endl;
	cout << "string:" << str1.c_str() << " find:\'0\', at pos: " << str1.find('0', 0) << endl;
	cout << "string:" << str1.c_str() << " find:\"abcde\", at pos: " << str1.find("abcde", 0) << endl;

	string str2 = "123456abcd";
	cout << "string:" << str2.c_str() << " pos == 3, len = 3, substring == " << str2.substr(3, 3).c_str() << endl;
	cout << "string:" << str2.c_str() << " pos == 3, len = 100, substring == " << str2.substr(3, 100).c_str() << endl;
	cout << "string:" << str2.c_str() << " pos == 3, len = npos, substring == " << str2.substr(3, string::npos).c_str() << endl;
}

void test05()// operator<<, operator>>
{
	string str;
	cout << "cin >> str;" << endl;
	cout << "cout << str << endl;" << endl;
	cout << "str == ";
	cin >> str;
	cout << str << endl;
}

int main()
{
	//test01();
	//test02();
	//test03();
	//test04();
	test05();

	return 0;
}